package com.github.sbb.sherry.primitives.core;

import com.github.sbb.sherry.primitives.api.BaseParamConverter;
import java.util.HashMap;
import java.util.Map;

public class BaseConverterPool {

  private static Map<String, BaseParamConverter> pool = new HashMap<>();

  private BaseConverterPool() {
  }

  public static BaseParamConverter getByParamType(String paramType) {
    return pool.get(paramType);
  }

  public static void registerConverter(Class<? extends BaseParamConverter> converter) {
    try {
      BaseParamConverter newInstance = converter.newInstance();
      pool.put(newInstance.paramType(), newInstance);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

}
